#include <vector>
#include <string>

#include "modules/common/configs/config_gflags.h"
#include "modules/map/proto/map.pb.h"

//#include "/apollo/Apollo_cmake_version/apollo_standalone/src/apollo/modules/map/proto/map.pb.h"
#include "modules/common/util/string_util.h"

#include "modules/map/hdmap/adapter/opendrive_adapter.h"
#include "modules/map/hdmap/adapter/odr_adapter.h"
#include "modules/map/hdmap/hdmap_impl.h"

#include "matplotlibcpp.hpp"




int main(){

  apollo::hdmap::adapter::OpendriveAdapter paser;
  

  //auto pb_map= new  apollo::hdmap::Map;

//   std::string map_filename="/home/zy/Desktop/apollo_standalone/src/apollo/modules/map/hdmap/test-data/base_map.bin";
  
//   //paser.LoadData(map_filename, pb_map);
//  // FLAGS_base_map_filename
//  paser.LoadData(FLAGS_base_map_filename, pb_map);
// //////////////////////////////////////////////

// use xml_parser
constexpr char kMapFilename[] = "../../apollo/modules/map/hdmap/test-data/base_map.bin";

apollo::hdmap::HDMapImpl hdmap_impl_;
hdmap_impl_.LoadMapFromFile(kMapFilename);



// use xodr_parser
// constexpr char xodr_MapFilename[] = "../../apollo/modules/map/hdmap/test-data/base_map.xodr";
// apollo::hdmap::HDMapImpl hdmap_impl_xodr;
// hdmap_impl_xodr.LoadMapFromFile(xodr_MapFilename);
//hdmap_impl_xodr.get_pbMap();



// load data from odr_parser
constexpr char xodr_MapFilename[] = "../../apollo/modules/map/hdmap/test-data/base_map.xodr";
auto pb_map= new  apollo::hdmap::Map;

apollo::hdmap::adapter::OdrAdapter odr_adapter;
odr_adapter.LoadData(xodr_MapFilename,pb_map);

// for(int i=0;i<pb_map->road_size();i++   ){
//       // road
//       pb_map->road(i);
//       // road_section
//       for(int j=0;j<pb_map->road(i).section_size();j++){
//           pb_map->road(i).section(j);
//            // lane
//           for(int k=0;k<pb_map->road(i).section(j).lane_id_size();k++){
//             std::cout<<"  Lane ID  "<<pb_map->road(i).section(j).lane_id(k).id()
//                      <<std::endl;
//           }
//       }
//     }


    std::vector<double> x_central_start_ENU;
    std::vector<double> y_central_start_ENU;
    x_central_start_ENU.clear();
    y_central_start_ENU.clear();

    std::vector<double> x_central_points_ENU;
    std::vector<double> y_central_points_ENU;

for(int i=0;i<pb_map->lane_size();i++){
  std::cout<<"Land ID  "<<pb_map->lane(i).id().id()
          <<"  Has centeral_curve  "<<pb_map->lane(i).has_central_curve()
          <<"  Has left_boundary  "<<pb_map->lane(i).has_left_boundary()
          <<"  Has right_boundary  "<<pb_map->lane(i).has_right_boundary()  
          <<std::endl;

  for(int j=0;j<pb_map->lane(i).central_curve().segment_size();j++    ){
    // start point of each central_curve segment
x_central_start_ENU.push_back( pb_map->lane(i).central_curve().segment(j).start_position().x());
y_central_start_ENU.push_back(pb_map->lane(i).central_curve().segment(j).start_position().y());

    for(int k=0;k<pb_map->lane(i).central_curve().segment(j).line_segment().point_size();k++){
        x_central_points_ENU.push_back( pb_map->lane(i).central_curve().segment(j).line_segment().point(k).x());
        y_central_points_ENU.push_back(pb_map->lane(i).central_curve().segment(j).line_segment().point(k).y());
    }
  }        



}


// how to plot
    namespace plt = matplotlibcpp;

    plt::plot(x_central_start_ENU,y_central_start_ENU,"r."); //"ro"
    plt::plot(x_central_points_ENU,y_central_points_ENU,"b--");
    plt::show();
     plt::legend();


ADEBUG<<" parse_map_data_and_show";
return 0;

}